﻿using System;
using System.Collections.Generic;
using IllusionUtility.GetUtility;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

namespace Studio
{
	// Token: 0x020004C8 RID: 1224
	public class ItemFKCtrl : MonoBehaviour
	{
		// Token: 0x06001F30 RID: 7984 RVA: 0x000C27E0 File Offset: 0x000C09E0
		public void InitBone(OCIItem _ociItem, Info.ItemLoadInfo _loadInfo, bool _isNew)
		{
			Transform transform = _ociItem.objectItem.transform;
			_ociItem.listBones = new List<OCIChar.BoneInfo>();
			foreach (string text in _loadInfo.bones)
			{
				GameObject gameObject = transform.FindLoop(text);
				if (gameObject == null)
				{
					GlobalData.Debug_LogWarning(string.Format("无 : {0}", text));
				}
				else
				{
					OIBoneInfo oiboneInfo = null;
					if (!_ociItem.itemInfo.bones.TryGetValue(text, out oiboneInfo))
					{
						oiboneInfo = new OIBoneInfo(Studio.GetNewIndex());
						_ociItem.itemInfo.bones.Add(text, oiboneInfo);
					}
					GuideObject guideObject = Singleton<GuideObjectManager>.Instance.Add(gameObject.transform, oiboneInfo.dicKey);
					guideObject.enablePos = false;
					guideObject.enableScale = false;
					guideObject.enableMaluti = false;
					guideObject.calcScale = false;
					guideObject.scaleRate = 0.5f;
					guideObject.scaleRot = 0.025f;
					guideObject.scaleSelect = 0.05f;
					guideObject.parentGuide = _ociItem.guideObject;
					_ociItem.listBones.Add(new OCIChar.BoneInfo(guideObject, oiboneInfo));
					guideObject.SetActive(false, true);
					this.listBones.Add(new ItemFKCtrl.TargetInfo(gameObject, oiboneInfo.changeAmount, _isNew));
				}
			}
		}

		// Token: 0x06001F31 RID: 7985 RVA: 0x000C295C File Offset: 0x000C0B5C
		private void Start()
		{
			this.LateUpdateAsObservable().Subscribe(delegate(Unit _)
			{
				foreach (ItemFKCtrl.TargetInfo targetInfo in this.listBones)
				{
					targetInfo.Update();
				}
			}).AddTo(this);
		}

		// Token: 0x06001F32 RID: 7986 RVA: 0x000C297C File Offset: 0x000C0B7C
		private void OnDisable()
		{
			foreach (ItemFKCtrl.TargetInfo targetInfo in this.listBones)
			{
				targetInfo.CopyBase();
			}
		}

		// Token: 0x0400210A RID: 8458
		private List<ItemFKCtrl.TargetInfo> listBones = new List<ItemFKCtrl.TargetInfo>();

		// Token: 0x020004C9 RID: 1225
		private class TargetInfo
		{
			// Token: 0x06001F34 RID: 7988 RVA: 0x000C2A34 File Offset: 0x000C0C34
			public TargetInfo(GameObject _gameObject, ChangeAmount _changeAmount, bool _new)
			{
				this.gameObject = _gameObject;
				this.changeAmount = _changeAmount;
				if (_new)
				{
					this.CopyBone();
				}
				this.baseRot = this.transform.localEulerAngles;
			}

			// Token: 0x17000389 RID: 905
			// (get) Token: 0x06001F35 RID: 7989 RVA: 0x000C2A74 File Offset: 0x000C0C74
			public Transform transform
			{
				get
				{
					if (this.m_Transform == null)
					{
						this.m_Transform = this.gameObject.transform;
					}
					return this.m_Transform;
				}
			}

			// Token: 0x06001F36 RID: 7990 RVA: 0x000C2AA0 File Offset: 0x000C0CA0
			public void CopyBone()
			{
				this.changeAmount.rot = this.transform.localEulerAngles;
			}

			// Token: 0x06001F37 RID: 7991 RVA: 0x000C2AB8 File Offset: 0x000C0CB8
			public void CopyBase()
			{
				this.transform.localEulerAngles = this.baseRot;
			}

			// Token: 0x06001F38 RID: 7992 RVA: 0x000C2ACC File Offset: 0x000C0CCC
			public void Update()
			{
				this.transform.localRotation = Quaternion.Euler(this.changeAmount.rot);
			}

			// Token: 0x0400210B RID: 8459
			public GameObject gameObject;

			// Token: 0x0400210C RID: 8460
			private Transform m_Transform;

			// Token: 0x0400210D RID: 8461
			public ChangeAmount changeAmount;

			// Token: 0x0400210E RID: 8462
			private Vector3 baseRot = Vector3.zero;
		}
	}
}
